var optionVisit = {
    columns: [{
        field: 'logId',
        title: '日志 ID'
    }, {
        field: 'logContent',
        title: '日志内容'
    }, {
        field: 'userId',
        title: '用户 ID'
    }, {
        field: 'userName',
        title: '用户名称'
    }, {
        field: 'userIP',
        title: '用户IP'
    }, {
        field: 'userMac',
        title: '用户MAC'
    }, {
        field: 'logTime',
        title: '日志时间',
        width: '90'
    }]
};

var optionOper = {
    columns: [{
        field: 'logId',
        title: '日志 ID'
    }, {
        field: 'logContent',
        title: '日志内容'
    }, {
        field: 'userId',
        title: '用户 ID'
    }, {
        field: 'userName',
        title: '用户名称'
    }, {
        field: 'logTime',
        title: '日志时间'
    }]
};
$(document).delegate("#btnSearch", "click", function () {
    var option = optionVisit;
    if("oper" == $("#logType").val()){
        option = optionOper;
    }
    $("#table").bootstrapTable('refreshOptions', option);
});

function initUserTable() {
    var url = "/manage/log/list";
    $('#table').bootstrapTable({
        url: url,
        striped: true,
        cache: false,
        pagination: true,
        sidePagination: "server",
        toolbar: "#toolbar",
        pageList: [10, 25, 50, 100],
        columns: optionVisit.columns,
        responseHandler: function (res) {
            return res.data;
        },
        queryParams: function (params) {
            var searchkey = $.trim($("#searchkey").val());
            var logType = $("#logType").val();
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            var temp = {
                pageSize: params.limit,
                pageNum: (params.offset / params.limit) + 1,
                sort: params.sort,
                searchkey: searchkey,
                logType: logType,
                startTime: startTime,
                endTime: endTime
            };
            return temp;
        },
    });
}


/**
 * 初始化日期控件
 *
 * @Author wucm
 * @Date 2018/1/6
 */
function initLaydate() {
    laydate.render({
        elem: '#startTime'
    });

    laydate.render({
        elem: '#endTime'
    });
}

function exportDialog() {
    BootstrapDialog.show({
        title: '导出确认',
        message: '请再次确认是否进行导出操作？',
        type: BootstrapDialog.TYPE_DANGER,
        buttons: [{
            label: '确定',
            cssClass: 'btn-danger',
            action: function (dialog) {
                var searchkey = $.trim($("#searchkey").val());
                var logType = $("#logType").val();
                var startTime = $("#startTime").val();
                var endTime = $("#endTime").val();
                var param = {
                    searchkey: searchkey,
                    logType: logType,
                    startTime: startTime,
                    endTime: endTime
                };
                Base.executeExport("/manage/log/export", param);
                dialog.close();
            }
        }, {
            label: '取消',
            action: function (dialog) {
                dialog.close();
            }
        }]
    });
}

